import { createStore } from 'vuex'
import { IUserInfo, IMenu } from '@/api/types/common'
import createPersistedState from 'vuex-persistedstate'

const state = {
  isCollapse: false,
  user: null as ({ token: string } & IUserInfo) | null,
  menus: [] as IMenu[]
}
export type State = typeof state
export const store = createStore<State>({
  plugins: [createPersistedState()],
  state,
  mutations: {
    setIsCollapse (state:State, payload:any) {
      state.isCollapse = payload
    },
    setUser (state:State, plyload:any) {
      state.user = plyload
    },
    setMenus (state, payload) {
      state.menus = payload
    }
  }
})

export default store
